from sqlalchemy import Column, String, Integer, ForeignKey
from sqlalchemy.orm import relationship

from models.participation import Participation
from . import Base


class User(Base):
    __tablename__ = "users"

    uid = Column(String(36), primary_key=True, index=True)
    nick = Column(String(32))
    passwd = Column(String(64))
    email = Column(String(64), unique=True)
    last_login = Column(Integer)
    openid = Column(String(64), unique=True)

    # events = relationship(
    #     "Event",
    #     secondary=Participation.__tablename__,
    #     back_populates="users"
    # )

    role_id = Column(Integer, default=1)

    def __repr__(self):
        return f"<User(uid={self.uid}, username={self.username}, role_id={self.role_id})>"
